/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SRMI.Tests;

import java.io.File;

/**
 *
 * @author meemo
 */
public class Test {
    public static void main(String[] args) throws Exception {
        Process p = null;
        try
        {
            if(args.length < 1)
            {
                System.out.println("Usage: java -ea -Djava.system.class.loader=SRMI.Tests.SRMIClassLoader -jar SRMI.jar [server|client|indrclient]");
                return;
            }
            
            String basedir = null;

            if(System.getProperty("srmi.basedir") == null)
            {
                basedir = new File(".").getAbsolutePath();
                basedir = basedir.substring(0,basedir.length()-2);
                System.out.println("Setting srmi.basedir to " + basedir);
                System.setProperty("srmi.basedir", basedir);
            }
            
            if(SRMIClassLoader.getInstance() != null)
            {
                System.out.println("SRMIClassLoader is intact");
                SRMIClassLoader.getInstance().SetPath(basedir);
            }
            else
                System.out.println("SRMIClassLoader is NOT intact");

            if(args[0].equalsIgnoreCase("server"))
            {
                MyServer.main(new String[]{});
            }        
            else if(args[0].equalsIgnoreCase("client"))
            {
                MyClient.main(new String[]{});
            }
            else if(args[0].equalsIgnoreCase("indrclient"))
            {
                MyIndirectClient.main(new String[]{});
            }
        }
        catch(Throwable ex)
        {
            System.out.println("Exception caught !");
            do{
            ex.printStackTrace();
            ex = ex.getCause();
            System.out.println("Caused by:");
            } while(ex != null);            
        }
    }    
}
